package org.jeecgframework.codegenerate.generate;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//a.a
public class TemplateConfig {
	private static final Logger logger = LoggerFactory.getLogger(TemplateConfig.class);
	private String templatePath;
	private List<File> templateRootDirs = new ArrayList<File>();
	private String stylePath;
	private String vueStyle;

	public TemplateConfig(String templatePath) {
		this.templatePath = templatePath;
	}

	private void addTemplateRootDirs(File file) {
		this.templateRootDirs.add(file);
	}

	private void setTemplateRootDirs(File... files) {
		this.templateRootDirs = Arrays.asList(files);
	}

	public void setTemplateRootDirs(List<File> templateRootDirs) {
		this.templateRootDirs = templateRootDirs;
	}
	
	public String getVueStyle() {
		return this.vueStyle;
	}

	public void setVueStyle(String vueStyle) {
		this.vueStyle = vueStyle;
	}

	public String getStylePath() {
		return this.stylePath;
	}

	public void setStylePath(String stylePath) {
		this.stylePath = stylePath;
	}

	
	
	public List<File> getTemplateRootDirs() {
		URL url = this.getClass().getResource(this.templatePath);
		if (url == null) {
			throw new RuntimeException("加载代码生成器模板失败，路径 ‘" + this.templatePath + "’ 不存在！");
		}
		String filePath = this.getClass().getResource(this.templatePath).getFile();
		try {
			filePath = URLDecoder.decode(filePath, "utf-8");
		} catch (UnsupportedEncodingException var4) {
		}
		filePath = filePath.replaceAll("%20", " ");
		if (filePath.indexOf("/BOOT-INF/classes!") != -1 || filePath.indexOf("/BOOT-INF/lib/") != -1 || filePath.indexOf(".jar!") != -1) {
			filePath = System.getProperty("user.dir") + File.separator + "config/jeecg/code-template-online/".replace("/", File.separator);
		}
		this.addTemplateRootDirs(new File(filePath));
		return this.templateRootDirs;
	}

	public String toString() {
		StringBuilder var1 = new StringBuilder();
		var1.append("{\"templateRootDirs\":\"");
		var1.append(this.templateRootDirs);
		var1.append("\",\"stylePath\":\"");
		var1.append(this.stylePath);
		var1.append("\",\"vueStyle\":\"");
		var1.append(this.vueStyle);
		var1.append("\"} ");
		return var1.toString();
	}
}
